﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Torch_Common.Helpes;

namespace WebApp.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        [HttpGet]
        public async Task<object> GetJwtStr(string name, string pass)
        {
            //将用户id和角色名作为单独的定义变量，封装进token字符串中。
            TokenModelJwt tokenModel = new TokenModelJwt { Uid = 1, Role = "Admin" };
            var jwtStr = JwtHelper.IssueJwt(tokenModel); //登录，获取到一定规则的Token令牌
            var suc = true;
            return Ok(new
            {
                success = suc,
                token = jwtStr
            });

        }
        [Authorize(Policy = "Admin")]
        [HttpGet]
        public string GetString() 
        {
            return "同一种调调";
        }
    }
}
